home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / inventor / SpaceballViewer / MyTextureEditor.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  8.9 KB  |  250 lines

  1. /*
  2.  * Copyright (c) 1991-94 Silicon Graphics, Inc.
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that the name of Silicon Graphics may not be used in any advertising or
  7.  * publicity relating to the software without the specific, prior written
  8.  * permission of Silicon Graphics.
  9.  *
  10.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
  11.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
  12.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  13.  *
  14.  * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  15.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
  16.  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF THE
  17.  * POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN
  18.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  19.  */
  20. //  -*- C++ -*-
  21.  
  22. /*
  23.  * Copyright (C) 1991-93   Silicon Graphics, Inc.
  24.  *
  25.  _______________________________________________________________________
  26.  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
  27.  |
  28.  |   $Revision: 1.15 $
  29.  |
  30.  |   Description:
  31.  |    Component which lets you specify and edit a texture for an object
  32.  |
  33.  |   Classes:     MyTextureEditor
  34.  |
  35.  |   Author(s): Alain Dumesny
  36.  |
  37.  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
  38.  _______________________________________________________________________
  39.  */
  40.  
  41. #ifndef _MY_TEXTURE_EDITOR_
  42. #define _MY_TEXTURE_EDITOR_
  43.  
  44. #include <X11/Intrinsic.h>
  45. #include <Xm/Xm.h>
  46. #include <GL/glx.h>
  47. #include <Inventor/Xt/SoXtComponent.h>
  48. #include <Inventor/misc/SoCallbackList.h>
  49. #include <Inventor/SbPList.h>
  50.  
  51. class SoPath;
  52. class SoSensor;
  53. class SoNodeSensor;
  54. class SoTexture2;
  55. class SoTexture2Transform;
  56. class SoTextureCoordinateFunction;
  57. class SoNode;
  58. class SoSeparator;
  59. class SoXtExaminerViewer;
  60. class MyColorWheel;
  61. class MyColorSlider;
  62. class MyThumbWheel;
  63.  
  64. struct TextureNameStruct;
  65. class MyTextureEditor;
  66.  
  67. // callback function prototypes
  68. typedef void MyTextureEditorCB(void *userData, MyTextureEditor *editor);
  69.  
  70.  
  71. //////////////////////////////////////////////////////////////////////////////
  72. //
  73. //  Class: MyTextureEditor
  74. //
  75. //  This editor components lets you interactively specify a texture map to
  76. //  use (from palettes of textures) as well as modify how the texture is
  77. //  applied to the object (translate, rotate, scale as well as different 
  78. //  mapping and other functions).
  79. //
  80. //////////////////////////////////////////////////////////////////////////////
  81.  
  82. class MyTextureEditor : public SoXtComponent {
  83.   public:
  84.     
  85.     // Pass the home directory of the texture palettes to use.
  86.     // By default the system installed location is used, in addition
  87.     // to looking at the SO_TEXTURE_DIR environment variable.
  88.     //
  89.     MyTextureEditor(
  90.     Widget parent = NULL,
  91.     const char *name = NULL, 
  92.     SbBool buildInsideParent = TRUE, 
  93.     const char *dir = NULL);
  94.    ~MyTextureEditor();
  95.     
  96.     //
  97.     // specify the geometry to display as textured map in the editor
  98.     // viewing window.
  99.     //
  100.     void    setObjectGeometry(SoNode *geomRoot);
  101.     
  102.     //
  103.     // set/get the SoTexture2 and the SoTextureCoordinateFunction nodes.
  104.     // Those routines should be used in conjunction to the callbacks to
  105.     // set and get the editor's texture nodes.
  106.     //
  107.     void    setTextureNode(const SoTexture2 *txtNode);
  108.     const SoTexture2 *getTextureNode() const        { return texNode; }
  109.     
  110.     void    setTransformNode(const SoTexture2Transform *xf);
  111.     const SoTexture2Transform *getTransformNode() const
  112.                             { return texXfNode; }
  113.     
  114.     void    setFunctionNode(const SoTextureCoordinateFunction *func);
  115.     const SoTextureCoordinateFunction *getFunctionNode() const
  116.                             { return texFuncNode; }
  117.     
  118.     //
  119.     // Callbacks - register functions that will be called whenever the user
  120.     // accepts the current texture settings (press the accept button).
  121.     //
  122.     // Note: the Editor class pointer is passed as the callback data, so
  123.     // the user should use the get methods to access the texture nodes
  124.     //
  125.     void    addCallback(
  126.                 MyTextureEditorCB *f,
  127.         void *userData = NULL)
  128.     { callbackList.addCallback((SoCallbackListCB *) f, userData);}
  129.     
  130.     void    removeCallback(
  131.                 MyTextureEditorCB *f,
  132.         void *userData = NULL)
  133.     { callbackList.removeCallback((SoCallbackListCB *) f, userData); }
  134.     
  135.   protected:
  136.  
  137.     // redefine these
  138.     virtual const char *    getDefaultWidgetName() const;
  139.     virtual const char *    getDefaultTitle() const;
  140.     virtual const char *    getDefaultIconTitle() const;
  141.     
  142.   private:
  143.     // scene graph and vars
  144.     SoSeparator        *sceneRoot;
  145.     SoTexture2        *texNode;
  146.     SoTexture2Transform *texXfNode;
  147.     SoTextureCoordinateFunction *texFuncNode;
  148.     SoNode        *userGeometry;
  149.     SbBool        repeatState;
  150.     
  151.     SoCallbackList    callbackList;
  152.     
  153.     void        updateTexture2UI();
  154.     void        updateTextureXfUI();
  155.     void        updateTextureFuncUI();
  156.     void        updateTextureFieldAndSlider(int fieldID);
  157.     SbBool        setRepeatState(SbBool flag);
  158.     
  159.     void        deselectCurrentItem(SbBool drawHighlight = TRUE);
  160.     void        updateTextureName();
  161.     void        updateTextureNode();
  162.     void        getPaletteNames();
  163.     void        loadPaletteItems();
  164.     void        savePalette();
  165.     void        deleteTextureEntry(int id);
  166.     SbBool        addTextureEntry(int id, char *fullName);
  167.     SbBool        readScaledImage(char *fileName, int xsize, int ysize, 
  168.             char *buf, int &zsize);
  169.     char        *readImage(char *file, int &xsize, int &ysize, int &zsize);
  170.     void        switchPalette(int id);
  171.     void        updateWindowTitle();
  172.     void        createNewPalette(char *palName);
  173.     
  174.     // component vars and callbacks
  175.     SbBool        ignoreCallback;
  176.     MyColorWheel    *colWheel;
  177.     MyColorSlider   *colSlider;
  178.     SoXtExaminerViewer *viewer;
  179.     MyThumbWheel    *scaleXThumb, *scaleYThumb;
  180.     float        oldXThumbVal, oldYThumbVal;
  181.     static void        colWheelCB(void *, const float hsv[3]);
  182.     static void        colSliderCB(void *, float);
  183.     static void        scaleXThumbCB(void *, float);
  184.     static void        scaleYThumbCB(void *, float);
  185.     
  186.     // Build routines
  187.     Widget        buildWidget(Widget parent);
  188.     Widget        buildMenu(Widget parent);
  189.     void        buildPaletteSubMenu();
  190.     Widget        buildPaletteMenuEntry(int id);
  191.     Widget        buildSliders(Widget parent);
  192.     Widget        buildButtons(Widget parent);
  193.     Widget        buildTexturePaletteWidget(Widget parent);
  194.  
  195.     // motif vars and callbacks
  196.     Widget        *widgetList;
  197.     SbBool        fieldChanged;
  198.     static void        fieldChangedCB(Widget, MyTextureEditor *, void *);
  199.     static void        fieldsCB(Widget, int, void *);
  200.     static void        slidersCB(Widget, int, void *);
  201.     static void        mappingMenuCB(Widget, int, void *);
  202.     static void        optionMenuCB(Widget, int, void *);
  203.     static void        acceptCB(Widget, MyTextureEditor *, void *);
  204.     
  205.     // menu vars and callbacks
  206.     void        createNewDialog();
  207.     void        createDeleteDialog(char *title, char *str1, char *str2);
  208.     void        updateFileMenu();
  209.     static void        fileMenuCB(Widget, int id, void *);
  210.     static void        paletteMenuCB(Widget w, int num, void *);
  211.     static void        newDialogCB(Widget, MyTextureEditor *, XmAnyCallbackStruct *);
  212.     static void        deleteDialogCB(Widget, MyTextureEditor *, XmAnyCallbackStruct *);
  213.     
  214.     // texture palette vars and callbacks
  215.     GLXContext        paletteCtx;
  216.     SbBool        loadedPalette;
  217.     char        *paletteDir;
  218.     Time        prevTime;
  219.     int            selectedItem, currentItem;
  220.     int            curPalette;
  221.     TextureNameStruct *textureNames;
  222.     SbPList        paletteList;
  223.     void        redrawPalette();
  224.     void        drawTextureTile(int id, int style);
  225.     void        handleEvent(XAnyEvent *xe);
  226.     static void        glxExposeCB(Widget, MyTextureEditor *, void *);
  227.     static void        glxInitCB(Widget, MyTextureEditor *, void *);
  228.     static void        glxEventCB(Widget, MyTextureEditor *, XAnyEvent *, Boolean *);
  229.     
  230.     // image dialog vars and callbacks
  231.     GLXContext        imageDialogCtx;
  232.     char        *dialogImage;
  233.     char        *dialogImageName, *dialogImageInfo;
  234.     int            dialogImageSize[3];
  235.     short        buttonsTotalWidth;
  236.     void        openImageDialog();
  237.     void        redrawImageDialog();
  238.     void        setNewDialogImage(char *fileName = NULL);
  239.     static void        imageDialogDestroyCB(Widget, MyTextureEditor *, void *);
  240.     static void        imageDialogExposeCB(Widget, MyTextureEditor *, void *);
  241.     static void        imageDialogInitCB(Widget, MyTextureEditor *, void *);
  242.     static void        imageDialogOpenCB(Widget, MyTextureEditor *, void *);
  243.     static void        imageDialogClearCB(Widget, MyTextureEditor *, void *);
  244.     static void        imageDialogApplyCB(Widget, MyTextureEditor *, void *);
  245.     static void        imageDialogCloseCB(Widget, MyTextureEditor *, void *);
  246.     static void        fileDialogOkCB(Widget, MyTextureEditor *, XmFileSelectionBoxCallbackStruct *);
  247. };
  248.  
  249. #endif // _MY_TEXTURE_EDITOR_
  250.